package org.reference.generic.operator;

import org.reference.generic.base.Parameter;

import util.Log;

/**
 * 
 */
public class Terminal extends Node {
    /**
     * 
     */
    public interface OnRequestParameterListenner {

        /**
         * @param requestParam 
         * @return
         */
        public abstract Parameter onRequestParameter(Parameter requestParam);

    }
    
    /**
     * 
     */
    public Terminal(Parameter parameters) {
    	super(parameters);
    	typeParam =parameters.getValueToString(Parameter.TYPE_TERM_VALUE);
    	setName(typeParam);
    	terminal = true;
    }

    private String typeParam;
    private OnRequestParameterListenner onRequestParamListenner;

    public void setOnRequestParameterListenner(OnRequestParameterListenner listenner) {
    	onRequestParamListenner = listenner;
    }

	@Override
	public double getResult() {
	
		if(typeParam.equals(Parameter.TYPE_VALUE_PT)){
			setName(getName()/*+String.valueOf(job.getProcessingTime())*/);
			
			Log.debug("잡   index "+ job.getJobIndex() + " PT"+ job.getProcessingTime());
			return job.getProcessingTime();
		}
		
		else if(typeParam.equals(Parameter.TYPE_VALUE_RM)){
			setName(getName()/*+String.valueOf(machine.getReadyTime())*/);
			Log.debug("머신 index " +machine.getIndex() + " RM" +machine.getReadyTime());
			return machine.getReadyTime();
		}
		
		else if(typeParam.equals(Parameter.TYPE_VALUE_CT)){
			setName(getName()/*+String.valueOf(machine.getTotalWorkingTime())*/);
			Log.debug("현재시간 CT "+machineManager.getCurrentTime());
			return machineManager.getCurrentTime();
		}		
		
//		if (onRequestParamListenner != null) {
//			Parameter respParam = onRequestParamListenner.onRequestParameter(typeParam);
//			value = respParam.getValueToDouble();
//		}		
//		setResult(value);
		
		return super.getResult();
	}

}